var currentIndexTemp = 0;
var indexTemp = 0;
var keyId;
var _rowIndex = 0;
efform_onload = function ()
{ 
	$('#ef_tab_y').hide();
};  

button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCH70","query");
}

button_update_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能对草拟的记录进行修改！"); return;
		}
	}
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCH70","update",true);
}

button_insert_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCH70","insert",true);
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCH70","delete",true);
	}); 
}

efgrid_onRowClicked = function( grid_id, row_index ){
	$('#ef_tab_y').show();
	if(grid_id == "ef_grid_result"){ 
		_rowIndex = row_index;
		var grid = efgrid.getGridObject(grid_id);
		keyId = grid.getCellValueByColumnName(row_index,"fdKeyId");
		year = grid.getCellValueByColumnName(row_index,"fdYear");
		month = grid.getCellValueByColumnName(row_index,"fdMonth");
		$('#keyId').val(keyId);
		$('#year').val(year); 
		$('#month').val(month); 
		fundiv(currentIndexTemp,indexTemp);
	}
};

/********************************************************************************
 ***********************************页签**************************************** 
 ********************************************************************************/
function fundiv(currentIndex,index){  
	currentIndexTemp = currentIndex;
	indexTemp = index;
	var year=$('#year').val();
	var month=$('#month').val();
	var keyId=$('#keyId').val();
	
	if(index ==0)
	{  
		var frame = frames[0];
		frame.src = "DispatchAction.do?efFormEname=ZMCH71"+"&keyId="+keyId+"&year="+year+"&month="+month;
		efform.setStatus(0, "正在加载...");
	}else if(index ==1)
	{ 
		var frame = frames[1];
		frame.src = "DispatchAction.do?efFormEname=ZMCH72"+"&keyId="+keyId+"&year="+year+"&month="+month;
		efform.setStatus(0, "正在加载...");
	} 
	else if(index ==2)
	{ 
		var frame = frames[2];
		frame.src = "DispatchAction.do?efFormEname=ZMCH73"+"&keyId="+keyId+"&year="+year+"&month="+month;
		efform.setStatus(0, "正在加载...");
	} 
} 

efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {

		
		var now = new Date();
		var year = now.getFullYear(); //年
		var month = now.getMonth() + 1; //月
		var day = now.getDate(); //日 
		var clock = year + "-";
		if (month < 10)
			clock += "0";
		clock += month + "-";
		if (day < 10)
			clock += "0";
		clock += day + " ";

		for (var i = 0; i < rows.length; i++) {
			grid.setCellValue(rows[i], 0, "0", TYPE_DATA); //状态			
			grid.setCellValue(rows[i], 1, year, TYPE_DATA); //年
			grid.setCellValue(rows[i], 2, month, TYPE_DATA);//月
			for (var j=3; j < 48; j++) { // 48为总列数
				grid.setCellValue(rows[i], j, "", TYPE_DATA);
			}
		}
	
	}
}
refresh_main_grid = function() {
	var ajax_callback =
	{
		onSuccess :
    		function(eiInfo)
			{
				grid = efgrid.getGridObject("ef_grid_result");
				grid.refresh(eiInfo);
				grid.setCurrentRowIndex(_rowIndex);
    		},
  		onFail:
    		function(eMsg)
			{
   				alert("服务调用失败: " + eMsg);
			}
	};

	var info = new EiInfo();

	info.setById("year");
	info.setById("month");
  	EiCommunicator.send( "ZMCH70", "query", info, ajax_callback );
}

button_report_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	
	var rows=grid.getCheckedRows();
	if (rows.length > 1) {
		EFAlert("一次只能上报一条记录！","警告"); return;
	}
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能上报草拟状态的生产进度！","警告"); return;
		}
	}
	
	EFConfirm('确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCH70","report",true);
	});
}
